<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('份额转让') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('变更类型')" prop="changeItem">
        <el-select v-model="queryParams.changeItem" :placeholder="$t('变更类型')" clearable>
          <el-option
            v-for="dict in changeItemOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('变更日期')" prop="transferDate">
        <DatePicker
          v-model="dateRange"
          type="daterange"
        />

      </el-form-item>
      <el-form-item :label="$t('转让人')" prop="transferor">
        <fund-lp-select
          v-model="queryParams.transferor"
          :fund-id="this.$route.query.id"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:transfer:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
        <el-button
          v-hasPermi="['fund:transfer:edit']"
          size="mini"
          type="warning"
          icon="el-icon-upload2"
          @click="$refs.importExcel.open = true"
        >{{ $t('导入') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="fundShareTransferList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('变更类型')" align="center" prop="changeItem" :formatter="changeItemFormat" />
      <el-table-column :label="$t('变更日期')" align="center" prop="transferDate" width="130">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ parseTime(scope.row.transferDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('转让人')" align="center" prop="transferorName" show-overflow-tooltip />
      <el-table-column :label="$t('变更认缴') + $t('金额单位')" align="center" prop="transferSubscription" width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.transferSubscription, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('变更实缴') + $t('金额单位')" align="center" prop="transferPaidIn" width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.transferPaidIn, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('受让人来源')" align="center" prop="assigneeSource" :formatter="assigneeSourceFormat" />
      <el-table-column :label="$t('受让人属性')" align="center" prop="assigneeProperty" :formatter="assigneePropertyFormat" />
      <el-table-column :label="$t('受让人')" align="center" prop="assigneeName" show-overflow-tooltip />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['fund:transfer:view']"
            size="small"
            type="text"
            icon="el-icon-view"
            @click="updateHandle(scope.row)"
          >{{ $t('查看') }}</el-button>
          <el-button
            v-hasPermi="['fund:transfer:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改份额转让对话框 -->
    <el-dialog :title="title" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundShareTransferForm ref="fundShareTransferForm" />
    </el-dialog>

    <importexcel
      ref="importExcel"
      template-route="/template/fundShareTransferTemplate.xlsx"
      upload-url="/transfer/fundShareTransfer/importData"
      :template-file-name="$t('份额变更导入模板.xlsx')"
      :upload-before-method="uploadBeforeMethod"
      :other-message-list="[$t('提示2: 导入数据不会影响现有出资人信息, 最新变更数据请通过列表新增进行录入!')]"
    />
  </div>
</template>

<script>
import { listFundShareTransfer, delFundShareTransfer, exportFundShareTransfer } from '@/api/fund/transfer/fundShareTransfer'
import fundShareTransferForm from './fundShareTransferForm.vue'
import FundLpSelect from '@/components/Select/fundLpSelect'
import importexcel from '@/components/importexcel/index.vue'
export default {
    components: {
      importexcel,
      FundLpSelect,
      fundShareTransferForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 份额转让表格数据
          fundShareTransferList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
        // 变更项字典
        changeItemOptions: [],
        // 受让人来源字典
        assigneeSourceOptions: [],
        // 受让人属性
        assigneePropertyOptions: [],
          // 查询参数
          queryParams: {
              fundId: this.$route.query.id,
              changeItem: undefined,
              transferor: undefined,
              pageNum: 1,
              pageSize: 10
          },
        // 时间范围
        dateRange: [],
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('change_item').then(response => {
          this.changeItemOptions = response.data
      })
      this.getDicts('assignee_property').then(response => {
          this.assigneeSourceOptions = response.data
      })
    // 客户类型
    this.getDicts('lp_type').then(response => {
      this.assigneePropertyOptions = this.assigneePropertyOptions.concat(response.data)
    })
    // 主体类型
    this.getDicts('main_body_type').then(response => {
      this.assigneePropertyOptions = this.assigneePropertyOptions.concat(response.data)
    })
  },
  methods: {
    /** 查询份额转让列表 */
    getList() {
        this.loading = true
        listFundShareTransfer(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.fundShareTransferList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 变更项字典翻译
    changeItemFormat(row) {
      return this.selectDictLabel(this.changeItemOptions, row.changeItem)
    },
    // 受让人来源字典翻译
    assigneeSourceFormat(row) {
      return this.selectDictLabel(this.assigneeSourceOptions, row.assigneeSource)
    },
    assigneePropertyFormat(row) {
      return this.selectDictLabel(this.assigneePropertyOptions, row.assigneeProperty)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            fundId: undefined,
            changeItem: undefined,
            transferDate: undefined,
            transferor: undefined,
            transferSubscription: undefined,
            transferPaidIn: undefined,
            assigneeSource: undefined,
            assigneeProperty: undefined,
            assignee: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
      this.dateRange = undefined
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = this.$t('份额转让')
        this.$nextTick(() => {
            this.$refs.fundShareTransferForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = this.$t('份额转让')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.fundShareTransferForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delFundShareTransfer(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportFundShareTransfer(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    },
    uploadBeforeMethod() {
      var _this = this
      this.$confirm(this.$t('导入数据不会影响现有出资人信息，最新变更数据请通过列表新增进行录入！'), this.$t('提示'), {
        confirmButtonText: this.$t('继续导入'),
        cancelButtonText: this.$t('关闭'),
        type: 'warning'
      }).then(() => {
        _this.$refs.importExcel.submitUpload()
      }).catch(() => {
      })
    }
  }
}
</script>
